package radio.vnmedia.vn.utils.htmlparser;

import java.util.ArrayList;

public abstract class FindBarrier {
	private ArrayList<String> first_block;
	private ArrayList<String> caudal_block;
	private String text;
	private int block_index = 0;
	private String text_return;
	private BlockTextFinder btf;
	private int index = 0;

	/**
	 * This class use to find many strings in a text by the barriers. For
	 * example: I have a text content: |||d;s:d.|||f;s:d.|fdf.dfg| now I want to
	 * find the string inside sign '|' & '.' Then, my first barrier is '|' and
	 * caudal barrier is '.' first_barrier = {'|'} & caudal_barrier = {'.'}
	 * Output: ||d;s:d ||f;s:d fdf
	 * 
	 * If: first_barrier = {"|", ";"} & caudal_barrier = {".", ":"} Output:
	 * ||d;s:d ||f;s:d fdf s s
	 * 
	 * @param content
	 * @param first_barrier
	 * @param caudal_barrier
	 */
	public FindBarrier(String content, ArrayList<String> first_block, ArrayList<String> caudal_block) {
		this.first_block = first_block;
		this.caudal_block = caudal_block;
		text = content;
		index = 0;
	}

	public abstract void stringResult(String str, int index);

	public void findBarrier() {
		int fromIndex = 0;
		while (block_index < first_block.size()) {
			if (btf == null)
				btf = new BlockTextFinder(text, fromIndex, first_block.get(block_index), caudal_block.get(block_index));
			while (btf.hasNext()) {
				text_return = btf.getText();
				stringResult(text_return, index++);
			}
			fromIndex = btf.getEndIndex();
			btf = null;
			block_index++;
		}
	}
}